package com.fmatos.amazingwallpapers.service.alarm;

import com.fmatos.amazingwallpapers.image.network.Connectivity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class AlbumAlarmReceiver extends BroadcastReceiver {

	private static final String TAG = AlbumAlarmReceiver.class.getSimpleName();
	
    @Override
    public void onReceive(Context context, Intent intent) {
    	
    	Log.i(TAG," receive");
        if (intent != null ) {
        	if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction() )) {
        
        		AlbumAlarm alarm = new AlbumAlarm(context);
        		alarm.setRecurringTimeAlarm();
        		Toast.makeText(context, TAG, Toast.LENGTH_LONG).show();
        		Log.i(TAG," set alarm from boot");
        	

        	} else if (AlbumAlarm.BROADCAST_ACTION_RECURRING.equals(intent.getAction())) { 
            	
        		runRecurringAction(context);
            	
            	
//        	} else if (AlbumAlarm.BROADCAST_ACTION_DOWNLOAD_INFO.equals(intent.getAction())) {
//
//        		downloadImages(context);
        	}
        }
    }
    
//    private void downloadImages(Context context) {
//		// TODO Auto-generated method stub
//		Toast.makeText(context, AlbumAlarm.BROADCAST_ACTION_DOWNLOAD_INFO, Toast.LENGTH_LONG).show();
//		Log.i(TAG,AlbumAlarm.BROADCAST_ACTION_DOWNLOAD_INFO);
//	}

	private void runRecurringAction(Context context) {
		

    	String message = "Amazing Wallpapers detected";
		if ( Connectivity.isConnectedWifi(context) ) {
			message += " wifi on";
		} else if ( Connectivity.isConnected(context)){
			message += " wifi off, but connected somehow";
		} else {
			message += " connectivity is off";
		}
		
		Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    	Log.i(TAG,AlbumAlarm.BROADCAST_ACTION_DOWNLOAD_INFO);
		
	}

}
